package com.zq.myapp;

import android.content.Context;

import com.android.volley.Response;
import com.android.volley.VolleyError;

public abstract class VolleyInterface {

    public Context mContext;
    public static Response.Listener mListener;
    public static Response.ErrorListener mErrorListener;

    public VolleyInterface(Context context,Response.Listener<String> listener,
                Response.ErrorListener errorListener){
        this.mContext=context;
        this.mListener =listener;
        this.mErrorListener = errorListener;
    }

    public abstract void onMySuccess(String result);
    public abstract void onMyError(VolleyError error);

    public Response.Listener<String> loadingListener(){
        mListener = new Response.Listener<String>() {//监听成功
            @Override
            public void onResponse(String s) {
                //弹出加载中对话框
                onMySuccess(s);
            }
        };
        return mListener;
    }

    public Response.ErrorListener errorListener(){
        mErrorListener = new Response.ErrorListener() {//监听失败
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                onMyError(volleyError);
                //提示加载失败
            }
        };
        return mErrorListener;
    }

}
